<template>
  <div>
    <Searchbar>
      <el-input @change="getList" v-model="search.experiment_name" placeholder="请输入实验名称"></el-input>
      <el-input @change="getList" v-model="search.report_name" placeholder="请输入实验报告名称"></el-input>
      <el-select @change="onStatusChange" v-model="search.status" placeholder="请选择用户状态">
        <el-option v-for="item in status" :key="item.value" :label="item.label" :value="item.value"></el-option>
      </el-select>
      <el-input @change="getList" v-model="search.studentid" placeholder="请输入用户学号"></el-input>
      <el-input @change="getList" v-model="search.student_name" placeholder="请输入用户姓名"></el-input>
      <el-button class="search-btn" @click="getList" type="primary">查询</el-button>
    </Searchbar>

    <el-table :data="tableData" @selection-change="handleSelectionChange" style="width: 100%">
      <el-table-column fixed="left" type="selection" width="55"></el-table-column>
      <el-table-column fixed="left" type="index" label="序号" width="55"></el-table-column>
      <el-table-column prop="id" label="ID"></el-table-column>
      <el-table-column prop="report_title" label="实验报告名称"></el-table-column>
      <el-table-column prop="belong_experiment" label="实验名称"></el-table-column>
      <el-table-column prop="report_status" label="状态"></el-table-column>
      <el-table-column prop="studentID" label="用户学号"></el-table-column>
      <el-table-column prop="username" label="用户姓名"></el-table-column>
      <el-table-column prop="score" label="实验成绩"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button @click="goJudge(scope.row)" size="small" class="text-default">评分</el-button>
          <el-button @click="onExport(scope.row)" size="small" class="text-warning">导出报告</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next, jumper"
      @current-change="handleCurrentChange"
      @size-change=handleSizeChange
      :current-page.sync="search.page"
      :page-size="search.page_size"
      :total="total"
    ></el-pagination>
  </div>
</template>
<script>
import CreateFilter from "@/mixins/CreateFilter";
import pageMixin from "@/mixins/pageMixin";
import selectionChang from "@/mixins/selectionChang";
import { reportModel } from "@/api/models";
import Searchbar from "@/components/Searchbar";
export default {
  mixins: [CreateFilter, pageMixin, selectionChang],
  components: { Searchbar },
  data() {
    return {
      tableData: [],
      total: 0,
      search: {
        experiment_name: null,
        report_name: null,
        status: null,
        studentid: null,
        student_name: null,
        page: 1,
        page_size: 10,
      },
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      console.log("getList");
      reportModel.list(
        this.search,
        (res) => {
          this.total = res.total_records;
          this.tableData = res.data.map((v) => {
            v.status_label = this.statusToLabel(v.status);

            return v;
          });
        },
        (err) => {
          console.log(err);
        }
      );
    },
    goJudge(row) {
      this.$router.push('/report/judge/' + row.id);
    },
    onExport(row){
      // todo get download token and open new tag to download zip file of report
      window.open('/api/object/report/download/' + row.id, '_blank')
    }
  },
};
</script>
<style lang="scss">
</style>